package com.navi.loaddata.loadService.impl.measureData.cell1;

import com.navi.loaddata.core.gpEntity.GpChipF;
import com.navi.loaddata.core.gpEntity.GpDefectF;
import com.navi.loaddata.core.gpEntity.GpGlassF;
import com.navi.loaddata.core.gpEntity.MppLayoutPnlD;
import com.navi.loaddata.core.oracleEntity.EtlChipV;
import com.navi.loaddata.core.oracleEntity.EtlDefectV;
import com.navi.loaddata.core.oracleEntity.EtlGlassV;
import com.navi.loaddata.core.repository.impl.MesRepositoryImpl;
import com.navi.loaddata.core.util.CoordTransformService;
import com.navi.loaddata.core.util.CorrdTransformException;
import com.navi.loaddata.core.util.LoggerUtil;
import com.navi.loaddata.core.util.ProcessUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author jay
 */
@Service
public class ProcessDefectDataServiceCELL1 {
    @Autowired
    private CoordTransformService coordTransformService;
    private static final Logger logger = LoggerFactory.getLogger(ProcessDefectDataServiceCELL1.class);
    @Autowired
    private MesRepositoryImpl mesdao;

    public List<EtlGlassV> processGlass(GpGlassF glass) throws Exception {
        List<EtlGlassV> etlGlassVList = new ArrayList<>();
            EtlGlassV glassEntity = new EtlGlassV();

            if ("A".equals(glass.getGlassId().substring(0,1))) {
                glassEntity.setComponentType("1");
            }else if("C".equals(glass.getGlassId().substring(0,1))) {
                glassEntity.setComponentType("4");
            }else{
                glassEntity.setComponentType("10");
            }

            glassEntity.setStepId(ProcessUtil.processString(glass.getOpeId()));
//            glassEntity.setComponentId(ProcessUtil.processString(glass.getGlassId()));
            glassEntity.setGlassId(ProcessUtil.processString(glass.getGlassId()));
            Date procEndTime = new Date(glass.getProcEndTime().getTime());
            glassEntity.setGlassEndTime(procEndTime);
        if(!StringUtils.isEmpty(glass.getProcStartTime())) {
            glassEntity.setGlassStartTime(new Date(glass.getProcStartTime().getTime()));
        }
            glassEntity.setProductId(ProcessUtil.processString(glass.getProdId()));
            glassEntity.setProductVersion(null);
            glassEntity.setRouteId(null);
            glassEntity.setLotId(ProcessUtil.processString(glass.getLotId()));
            glassEntity.setEquipId(ProcessUtil.processString(glass.getEqptId()));
            glassEntity.setRunMode(null);
            glassEntity.setRecipeId(ProcessUtil.processString(glass.getRecipeId()));
            glassEntity.setSubEquipId(null);
            glassEntity.setOperatorId(ProcessUtil.processString(glass.getOperatorId()));
            glassEntity.setCstId(ProcessUtil.processString(glass.getCrrId()));
            glassEntity.setTaShift(glass.getShfId());
            glassEntity.setLotType(ProcessUtil.processString(glass.getLotType()));
            glassEntity.setOwnerId(ProcessUtil.processString(glass.getOwner()));
            //  glassEntity.setOwnerType(); //待处理
            glassEntity.setSlotNo(ProcessUtil.processString(glass.getSlotNo()));
            glassEntity.setAbnormalFlag(ProcessUtil.processString(glass.getAbnFlg()));
            glassEntity.setMesLinkKry(ProcessUtil.processString(glass.getMesLinkKey()));
            // glassEntity.setSamplingFlag(); //待处理
            glassEntity.setGlassJudge(ProcessUtil.processString(glass.getGlassJge()));
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date1 = glass.getProcEndTime();
            Date date2 = glass.getProcStartTime();
            glassEntity.setProcessTime(date1.getTime() - date2.getTime());
            glassEntity.setTactTime(ProcessUtil.getNumI(glass.getTactTime()));
            glassEntity.setTotalDftCount(ProcessUtil.getNumI(glass.getGlassDefectCnt()));
            glassEntity.setTotalImageCount(ProcessUtil.getNumI(glass.getGlassImgCnt()));
            //  glassEntity.setTotalReprDftQty(); //待处理
            glassEntity.setLcvdReprDftQty(ProcessUtil.getNumI(glass.getGlassLcvdRepDefectCnt()));
            glassEntity.setBackSideDftQty(ProcessUtil.getNumI(glass.getGlassBackDefectCnt()));
            glassEntity.setTestKetDftQty(ProcessUtil.getNumI(glass.getGlassTestKeyDefectCnt()));
            glassEntity.setAftStkDftQty(ProcessUtil.getNumI(glass.getGlassAfterStackDefectCnt()));
            glassEntity.setInkReprDftQty(ProcessUtil.getNumI(glass.getGlassInkRepDefectCnt()));
            glassEntity.setPnlCapDftQty(ProcessUtil.getNumI(glass.getGlassCaptureDefectCnt()));
            glassEntity.setTapReprDftQty(ProcessUtil.getNumI(glass.getGlassTapeRepDefectCnt()));
            glassEntity.setLsrReprDftQty(ProcessUtil.getNumI(glass.getGlassLaserRepDefectCnt()));
            glassEntity.setoDftQty(ProcessUtil.getNumI(glass.getGlassOSizeCnt()));
            glassEntity.setlDftQty(ProcessUtil.getNumI(glass.getGlassLSizeCnt()));
            glassEntity.setmDftQty(ProcessUtil.getNumI(glass.getGlassMSizeCnt()));
            glassEntity.setsDftQty(ProcessUtil.getNumI(glass.getGlassSSizeCnt()));
            glassEntity.setBrightDftQty(ProcessUtil.getNumI(glass.getGlassBrightDefectCnt()));
            glassEntity.setWriteDftQty(ProcessUtil.getNumI(glass.getGlassWhiteDefectCnt()));
            glassEntity.setGrayDftQty(ProcessUtil.getNumI(glass.getGlassGrayDefectCnt()));
            glassEntity.setBlackDftQty(ProcessUtil.getNumI(glass.getGlassDarkDefectCnt()));
            glassEntity.setScanAlignMark1Flg(ProcessUtil.getNum(glass.getScanAlignMark1Flg()));
            glassEntity.setScanAlignMark2Flg(ProcessUtil.getNum(glass.getScanAlignMark2Flg()));
            glassEntity.setScanAlignMark1X(ProcessUtil.getNum(glass.getScanAlignMark1XCoord()));
            glassEntity.setScanAlignMark1Y(ProcessUtil.getNum(glass.getScanAlignMark1YCoord()));
            glassEntity.setScanAlignMark2X(ProcessUtil.getNum(glass.getScanAlignMark2XCoord()));
            glassEntity.setScanAlignMark2Y(ProcessUtil.getNum(glass.getScanAlignMark2YCoord()));
            glassEntity.setCaptureAlignMark1Flg(ProcessUtil.getNum(glass.getCaptureAlignMark1Flg()));
            glassEntity.setCaptureAlignMark2Flg(ProcessUtil.getNum(glass.getCaptureAlignMark2Flg()));
            glassEntity.setCaptureAlignMark1X(ProcessUtil.getNum(glass.getCaptureAlignMark1XCoord()));
            glassEntity.setCaptureAlignMark1Y(ProcessUtil.getNum(glass.getCaptureAlignMark1YCoord()));
            glassEntity.setCaptureAlignMark2X(ProcessUtil.getNum(glass.getCaptureAlignMark2XCoord()));
            glassEntity.setCaptureAlignMark2Y(ProcessUtil.getNum(glass.getCaptureAlignMark2YCoord()));
            glassEntity.setResolRvHead1(ProcessUtil.processString(glass.getRewHeadResolution1()));
            glassEntity.setResolRvHead2(ProcessUtil.processString(glass.getRewHeadResolution2()));
            glassEntity.setResolRvHead3(ProcessUtil.processString(glass.getRewHeadResolution3()));
            glassEntity.setResolRvHead4(ProcessUtil.processString(glass.getRewHeadResolution4()));
            glassEntity.setResolRvHead5(ProcessUtil.processString(glass.getRewHeadResolution5()));
            glassEntity.setResolRvHead6(ProcessUtil.processString(glass.getRewHeadResolution6()));
            glassEntity.setCaptureSize(ProcessUtil.processString(glass.getCaptureSize()));
            glassEntity.setProbeCardId(ProcessUtil.processString(glass.getProbeCardId()));
            if(!StringUtils.isEmpty(glass.getRewkCnt())) {
                glassEntity.setReworkCnt(String.valueOf(glass.getRewkCnt()));
            }else {
                glassEntity.setReworkCnt("-1");
            }
            if ("A".equals(glass.getGlassId().substring(0,1))) {
                glassEntity.setArrayGlassId(glass.getGlassId());
                List<String> cfGlassId=mesdao.findBySQL("SELECT CFPRODUCTNAME FROM mes_product WHERE 1=1 and factoryname='OC' and productname ='"+glass.getGlassId()+"'");
                if(!cfGlassId.isEmpty()) glassEntity.setCfGlassId(cfGlassId.get(0));
            }else if("C".equals(glass.getGlassId().substring(0,1))){
                glassEntity.setCfGlassId(glass.getGlassId());
                List<String> arrayGlassId=mesdao.findBySQL("SELECT DestinationProductName FROM mes_product WHERE 1=1 and factoryname='OC' and productname ='"+glass.getGlassId()+"'");
                if(!arrayGlassId.isEmpty()) glassEntity.setArrayGlassId(arrayGlassId.get(0));
            }
            etlGlassVList.add(glassEntity);
        return etlGlassVList;
    }

    public List<EtlChipV> processPanel(List<GpChipF> gpPanelFList) throws Exception {
        List<EtlChipV> etlChipVList = new ArrayList<>();
            gpPanelFList.forEach(panel -> {
                EtlChipV panelEntity = new EtlChipV();
                panelEntity.setStepId(ProcessUtil.processString(panel.getOpeId()));
                panelEntity.setGlassId(ProcessUtil.processString(panel.getGlassId()));
                Date procEndTime = new Date(panel.getProcEndTime().getTime());
                panelEntity.setGlassEndTime(procEndTime);
                panelEntity.setChipId(ProcessUtil.processString(panel.getPanelId()));
                panelEntity.setChipNo(ProcessUtil.processString(panel.getPanelId().substring(panel.getPanelId().length()-2,panel.getPanelId().length())));//chipid
//                ldrArrayChipTEntity.setChipNo(panel.getPanelId().substring(panel.getPanelId().length()-2, panel.getPanelId().length()));//后2位
                panelEntity.setPanelJudge(ProcessUtil.processString(panel.getPnlJge()));
                panelEntity.setMainDefectCode(ProcessUtil.processString(panel.getPnlRejType()));
                panelEntity.setPanelGrade(ProcessUtil.processString(panel.getPnlGrade()));
                panelEntity.setChipTotalDftCount(ProcessUtil.getNumI(panel.getPnlDefectCnt()));
                panelEntity.setChipTotalImageCount(ProcessUtil.getNumI(panel.getPnlGlassImgCnt()));
                //     panelEntity.setChipTotalReprDftQty();    //待处理
                panelEntity.setChipLcvdReprDftQty(ProcessUtil.getNum(panel.getPnlLcvdRepDefectCnt().toString()));
                panelEntity.setChipBackSideDftQty(ProcessUtil.getNumI(panel.getPnlBackDefectCnt()));
                panelEntity.setChipTestKetDftQty(ProcessUtil.getNumI(panel.getPnlTestKeyDefectCnt()));
                panelEntity.setChipAftStkDftQty(ProcessUtil.getNumI(panel.getPnlAfterStackDefectCnt()));
                panelEntity.setChipInkReprDftQty(ProcessUtil.getNumI(panel.getPnlInkRepDefectCnt()));
                panelEntity.setChipPnlCapDftQty(ProcessUtil.getNumI(panel.getPnlCaptureDefectCnt()));
                panelEntity.setChipTapReprDftQty(ProcessUtil.getNumI(panel.getPnlTapeRepDefectCnt()));
                panelEntity.setChipLsrReprDftQty(ProcessUtil.getNumI(panel.getPnlLaserRepDefectCnt()));
                panelEntity.setChipODftQty(ProcessUtil.getNumI(panel.getPnlOSizeCnt()));
                panelEntity.setChipLDftQty(ProcessUtil.getNumI(panel.getPnlLSizeCnt()));
                panelEntity.setChipMDftQty(ProcessUtil.getNumI(panel.getPnlMSizeCnt()));
                panelEntity.setChipSDftQty(ProcessUtil.getNumI(panel.getPnlSSizeCnt()));
                panelEntity.setChipBrightDftQty(ProcessUtil.getNumI(panel.getPnlBrightDefectCnt()));
                panelEntity.setChipWriteDftQty(ProcessUtil.getNumI(panel.getPnlWhiteDefectCnt()));
                panelEntity.setChipGrayDftQty(ProcessUtil.getNumI(panel.getPnlGrayDefectCnt()));
                panelEntity.setChipBlackDftQty(ProcessUtil.getNumI(panel.getPnlDarkDefectCnt()));
                panelEntity.setNgPointDefNo(ProcessUtil.getNumI(panel.getNgPointDefCnt()));
                panelEntity.setNgShortDefNo(ProcessUtil.getNumI(panel.getNgShortDefCnt()));
                panelEntity.setNgOpenDefNo(ProcessUtil.getNumI(panel.getNgOpenDefCnt()));
                panelEntity.setPanelResetCnt(ProcessUtil.getNumI(panel.getPnlRetestCnt()));
                panelEntity.setPanelDefGCnt(ProcessUtil.getNumI(panel.getPnlDefGCnt()));
                panelEntity.setPanelDefNCnt(ProcessUtil.getNumI(panel.getPnlDefNCnt()));
                panelEntity.setPanelDefUnjdgCnt(ProcessUtil.getNumI(panel.getPnlDefUnjgeCnt()));
                panelEntity.setPanelVolChargeMeanP(ProcessUtil.processString(panel.getPnlVolMean().toString()));
                panelEntity.setPanelVolChargeStddevP(ProcessUtil.processString(panel.getPnlVolStd().toString()));
                panelEntity.setPanelVolMeanN(ProcessUtil.processString(panel.getPnlNegVolMean().toString()));
                panelEntity.setPanelVolSddevN(ProcessUtil.processString(panel.getPnlNegVolStd().toString()));

                etlChipVList.add(panelEntity);
            });
        return etlChipVList;
    }

    public List<EtlDefectV> processDefect(List<MppLayoutPnlD> layoutPnlDS, List<GpDefectF> gpDefectFList, Map<String, String> mOpeDList) throws Exception {
        List<EtlDefectV> etlDefectVList = new ArrayList<>();
            gpDefectFList.forEach(defect -> {
                EtlDefectV defectEntity = new EtlDefectV();
                defectEntity.setStepId(ProcessUtil.processString(defect.getOpeId()));
                defectEntity.setGlassId(ProcessUtil.processString(defect.getGlassId()));

                Date procEndTime = new Date(defect.getProcEndTime().getTime());
                defectEntity.setGlassEndTime(procEndTime);
                defectEntity.setDefectNo(String.valueOf(defect.getPanelId() + ProcessUtil.getLength4(defect.getDefectNo())));
                defectEntity.setChipId(ProcessUtil.processString(defect.getPanelId()));
                defectEntity.setChipNo(defect.getPanelId().substring(defect.getPanelId().length() - 2, defect.getPanelId().length()));
//                ldrArrayDefectTEntity.setItem1(defect.getrejecttype);
//                ldrArrayDefectTEntity.setDefectCode(defect.getcode);
                //item3
                String NASPath = "";
                String IMGPath = "";
                String[] listItem3 = defect.getFileUrl().split("\\\\");
                if (listItem3[0] == "") {

                } else {
//                NASPath = listItem3[0] + "\\" + listItem3[1] + "\\";//实际NAS路径
                    NASPath = "IMG;/acf;/";
                    switch (defect.getShopId()) {
                        case "ARRAY":
                            if (!StringUtils.isEmpty(defect.getDefectImg())&&defect.getDefectImg().indexOf("*")==-1) {//彩照
                                if ("A775".equals(defect.getOpeId().substring(0, 4)) && "ATST".equals(mOpeDList.get(defect.getOpeId()))) {
                                    IMGPath = "LCVD/IMAGES/" + defect.getLotId().substring(0, 5) + "/" + defect.getLotId() +"/"+ defect.getDefectImg() + ".JPG";
                                } else if ("A770".equals(defect.getOpeId().substring(0, 4)) && "ATST".equals(mOpeDList.get(defect.getOpeId()))) {
                                    IMGPath = "REPR/IMAGES/" + defect.getLotId().substring(0, 5) + "/" + defect.getLotId()+"/" + defect.getDefectImg() + ".JPG";
                                } else {//正常
                                    if ("AOI".equals(mOpeDList.get(defect.getOpeId()))) {
                                        IMGPath = defect.getProdId() + "/" + defect.getGlassId().substring(0, 5) + "/" + defect.getGlassId().substring(0, 8) + "/"
                                                + defect.getGlassId() + "/IMAGE/" + defect.getDefectImg() + ".JPG";
                                    } else if ("ATST".equals(mOpeDList.get(defect.getOpeId()))) {
                                        IMGPath = defect.getProdId() + "/" + defect.getGlassId().substring(0, 5) + "/" + defect.getGlassId().substring(0, 8) + "/"
                                                + defect.getGlassId() + "/IMAGE/" + defect.getDefectImg() + ".JPG";
                                    } else if ("LOI".equals(mOpeDList.get(defect.getOpeId()))) {
                                        IMGPath = defect.getProdId() + "/" + defect.getGlassId().substring(0, 5) + "/" + defect.getGlassId().substring(0, 8) + "/"
                                                + defect.getGlassId() + "/IMAGE/" + defect.getDefectImg() + ".JPG";
                                    }
                                }
                                defectEntity.setImageData(NASPath + IMGPath);
                            }
                            if (!StringUtils.isEmpty(defect.getGrayImgName())&&defect.getGrayImgName().indexOf("*")==-1) {//灰阶
                                IMGPath = defect.getProdId() + "/" + defect.getGlassId().substring(0, 5) + "/" + defect.getGlassId().substring(0, 8) + "/"
                                        + defect.getGlassId() + "/GRAYIMAGE/" + defect.getGrayImgName() + ".JPG";
                                defectEntity.setGrayimageData(NASPath + IMGPath);
                            }
                            break;
                        case "CF":
                            if (!StringUtils.isEmpty(defect.getDefectImg())&&defect.getDefectImg().indexOf("*")==-1) {//彩照
//                            if("A775".equals(defect.getOpeId().substring(0,4)) && "ATST".equals(mOpeDList.get(defect.getOpeId()))){
//                                IMGPath = "LCVD/IMAGES/" + defect.getLotId().substring(0, 5) + "/" + defect.getLotId() + "/ARRAYATST;" + defect.getDefectImg() + ".JPG";
//                            }else if(defect.getOpeId().substring(0,4)=="A770" && "ATST".equals(mOpeDList.get(defect.getOpeId()))){
//                                IMGPath = "REPR/IMAGES/" + defect.getLotId().substring(0, 5) + "/" + defect.getLotId() + "/ARRAYATST;" + defect.getDefectImg() + ".JPG";
//                            }else{//正常
                                if ("AOI".equals(mOpeDList.get(defect.getOpeId()))) {
                                    IMGPath = defect.getProdId() + "/" + defect.getGlassId().substring(0, 5) + "/" + defect.getGlassId().substring(0, 8) + "/"
                                            + defect.getGlassId() + "/IMAGE/" + defect.getDefectImg() + ".JPG";
                                } else if ("ATST".equals(mOpeDList.get(defect.getOpeId()))) {
                                    IMGPath = defect.getProdId() + "/" + defect.getGlassId().substring(0, 5) + "/" + defect.getGlassId().substring(0, 8) + "/"
                                            + defect.getGlassId() + "/IMAGE/" + defect.getDefectImg() + ".JPG";
                                } else if ("LOI".equals(mOpeDList.get(defect.getOpeId()))) {
                                    IMGPath = defect.getProdId() + "/" + defect.getGlassId().substring(0, 5) + "/" + defect.getGlassId().substring(0, 8) + "/"
                                            + defect.getGlassId() + "/IMAGE/" + defect.getDefectImg() + ".JPG";
//                                }
                                }
                                defectEntity.setImageData(NASPath + IMGPath);
                            }
                            if (!StringUtils.isEmpty(defect.getGrayImgName())&&defect.getGrayImgName().indexOf("*")==-1) {//灰阶
                                IMGPath = defect.getProdId() + "/" + defect.getGlassId().substring(0, 5) + "/" + defect.getGlassId().substring(0, 8) + "/"
                                        + defect.getGlassId() + "/GRAYIMAGE/" + defect.getGrayImgName() + ".JPG";
                                defectEntity.setGrayimageData(NASPath + IMGPath);
                            }
                            if (!StringUtils.isEmpty(defect.getBefRvrpImgName())&&defect.getBefRvrpImgName().indexOf("*")==-1) {//修补前
                                IMGPath = defect.getProdId() + "/" + defect.getGlassId().substring(0, 5) + "/" + defect.getGlassId().substring(0, 8) + "/"
                                        + defect.getGlassId() + "/IMAGE/" + defect.getBefRvrpImgName() + ".JPG";
                                defectEntity.setBeforeRvrpImageName(NASPath + IMGPath);
                            }
                            if (!StringUtils.isEmpty(defect.getAftRvrpImgName())&&defect.getAftRvrpImgName().indexOf("*")==-1) {//修补后
                                IMGPath = defect.getProdId() + "/" + defect.getGlassId().substring(0, 5) + "/" + defect.getGlassId().substring(0, 8) + "/"
                                        + defect.getGlassId() + "/IMAGE/" + defect.getAftRvrpImgName() + ".JPG";
                                defectEntity.setAfterRvrpImageName(NASPath + IMGPath);
                            }
                            break;
                        case "OC":
//                            NASPath = "IMG;/oc;/";
//                            if (!StringUtils.isEmpty(defect.getDefectImg())&&defect.getDefectImg().indexOf("*")==-1) {
//                                if ("L1160".equals(defect.getOpeId())||"L1162".equals(defect.getOpeId())||"L1240".equals(defect.getOpeId())||"L1260".equals(defect.getOpeId())||"L1262".equals(defect.getOpeId())||"L2140".equals(defect.getOpeId())) {
//                                    IMGPath = defect.getProdId()+"/"+defect.getGlassId().substring(0,5)+"/"+defect.getGlassId().substring(0,8)+"/"+defect.getGlassId()+"/IMAGE/"+defect.getDefectImg() + ".JPG";
//                                } else if ("AOI".equals(mOpeDList.get(defect.getOpeId()))) {
//                                    IMGPath = defect.getProdId()+"/"+defect.getGlassId().substring(0,5)+"/"+defect.getGlassId().substring(0,8)+"/"+defect.getGlassId()+"/IMAGE/"+defect.getDefectImg() + ".JPG";
//                                } else {//正常
//                                    if ("AOI".equals(mOpeDList.get(defect.getOpeId()))) {
//                                        IMGPath = defect.getProdId() + "/" + defect.getGlassId().substring(0, 5) + "/" + defect.getGlassId().substring(0, 8) + "/"
//                                                + defect.getGlassId() + "/IMAGE/" + defect.getDefectImg() + ".JPG";
//                                    } else if ("ATST".equals(mOpeDList.get(defect.getOpeId()))) {
//                                        IMGPath = defect.getProdId() + "/" + defect.getGlassId().substring(0, 5) + "/" + defect.getGlassId().substring(0, 8) + "/"
//                                                + defect.getGlassId() + "/IMAGE/" + defect.getDefectImg() + ".JPG";
//                                    } else if ("LOI".equals(mOpeDList.get(defect.getOpeId()))) {
//                                        IMGPath = defect.getProdId() + "/" + defect.getGlassId().substring(0, 5) + "/" + defect.getGlassId().substring(0, 8) + "/"
//                                                + defect.getGlassId() + "/IMAGE/" + defect.getDefectImg() + ".JPG";
//                                    }
//                                }
//                            }
                            break;
//                    default:
//                        defectEntity.setImageData(NASPath);
//                        break;
                    }
                }
                defectEntity.setDefectType("other");   //待处理
                defectEntity.setDefectCode(defect.getDefectCode()); //待处理
                // defectEntity.setImageData(); //上面已处理
                // defectEntity.setGrayimageData(); //上面已处理
                //  defectEntity.setAutoDefectCode();  //待处理
                //   defectEntity.setReason();  //待处理
                //  defectEntity.setMainDefectFlag(); //待处理
                //4-7
                defectEntity.setCellZone(ProcessUtil.processString(defect.getDefectZong()));      //zone      ??????
                defectEntity.setX(ProcessUtil.getNum(defect.getDefectXCoord()));
                defectEntity.setY(ProcessUtil.getNum(defect.getDefectYCoord()));
                // defectEntity.setX2();
                // defectEntity.setY2();
                //  defectEntity.setX3();
                // defectEntity.setY3();
                //numtitem3-6
                defectEntity.setS(ProcessUtil.getNum(defect.getDataNo()));
                defectEntity.setG(ProcessUtil.getNum(defect.getGateNo()));
                defectEntity.setDefSize(ProcessUtil.processString(defect.getDefectSize()));
                defectEntity.setSizeX(ProcessUtil.getNum(defect.getDefectXSize()));
                defectEntity.setSizeY(ProcessUtil.getNum(defect.getDefectYSize()));
                //  defectEntity.setDefectPattern();  //待处理
                defectEntity.setCcdid(ProcessUtil.processString(defect.getCcdId()));
                defectEntity.setOperatorIdRepr(ProcessUtil.processString(defect.getOperatorId()));
                defectEntity.setDefectFlag(ProcessUtil.processString2(defect.getDefectFlg()));
                defectEntity.setDefZone(ProcessUtil.processString(defect.getDefectZong()));
                defectEntity.setDefGrayLevelMax(ProcessUtil.getNum(defect.getAoiDefectGrayMax()));
                defectEntity.setDefGrayLevelMin(ProcessUtil.getNum(defect.getAoiDefectGrayMin()));
                defectEntity.setDefGrayLevelAvg(ProcessUtil.getNum(defect.getAoiDefectGrayAvg()));
                defectEntity.setDefGrayLevelRef(ProcessUtil.getNum(defect.getAoiDefectGrayRef()));
                defectEntity.setAdjPixelX(ProcessUtil.getNum(defect.getAdjXMuraVal()));
                defectEntity.setAdjPixelY(ProcessUtil.getNum(defect.getAdjYVcomLvl()));
                defectEntity.setAdjDftAreaSize(ProcessUtil.getNum(defect.getDefectAreaSize()));
                defectEntity.setAdjDftSizeX(ProcessUtil.getNum(defect.getAdjDefectXSize()));
                defectEntity.setAdjDftSizeY(ProcessUtil.getNum(defect.getAdjDefectYSize()));
                defectEntity.setDefZone(ProcessUtil.processString(defect.getDefectZong()));
                defectEntity.setAlarmTestKeyNo(ProcessUtil.getNum(defect.getAlarmTstKeyNo()));
                defectEntity.setInspections(ProcessUtil.processString(defect.getInspFlg()));
                defectEntity.setBeforeTapeValue(ProcessUtil.processString(defect.getBefTapeVal()));
                defectEntity.setAfterTapeValue(ProcessUtil.processString(defect.getAfterTapeVal()));
                //  defectEntity.setGrayDftQty(); //待处理
                defectEntity.setAoiDftImgName(ProcessUtil.processString(defect.getAoiDefectImgName()));
                // defectEntity.setBeforeRvrpImageName(ProcessUtil.processString(defect.getBefRvrpImgName()));//上面已处理
                //  defectEntity.setAfterRvrpImageName(ProcessUtil.processString(defect.getAftRvrpImgName()));  //上面已处理
                defectEntity.setBeforeInrpImageName(ProcessUtil.processString(defect.getBefInrpImgName()));
                defectEntity.setAfterInrpImageName(ProcessUtil.processString(defect.getAftInrpImgName()));
                //defectEntity.setRejudgeFlag();  //待处理
                //defectEntity.setDefectGlAve();  //待处理
                defectEntity.setTesterDefType1(ProcessUtil.processString(defect.getTestDefType1()));
                defectEntity.setTesterDefType2(ProcessUtil.processString(defect.getTestDefType2()));
                defectEntity.setDefResetFlg(ProcessUtil.processString(defect.getDefRetestFlg()));
                defectEntity.setRepairLineNo(ProcessUtil.processString(defect.getRepLineFlg()));
                defectEntity.setDefRealSize(ProcessUtil.processString(defect.getDefectAreaSize()));
                defectEntity.setDefLayer(ProcessUtil.processString(defect.getDefLayer().toString()));
                defectEntity.setLcvdRepairTime(ProcessUtil.processString(defect.getLcvdRepTime().toString()));
                defectEntity.setLcvdLen(ProcessUtil.processString(defect.getLcvdLength().toString()));
                defectEntity.setOperationId(ProcessUtil.processString(defect.getOperationId()));
                defectEntity.setLcvdType(ProcessUtil.processString(defect.getLcvdType()));
                // defectEntity.setReserved1();  //预留
                // defectEntity.setReserved2();   //预留
                defectEntity.setDefPictName(ProcessUtil.processString(defect.getDefImgName()));
                defectEntity.setAnalysModeCode(ProcessUtil.processString(defect.getAnalysisCode()));

                if ("C".equals(defect.getGlassId().substring(0,1))) {
                    defectEntity.setArrayX(-ProcessUtil.getNum(defect.getDefectXCoord()));
                }else if("A".equals(defect.getGlassId().substring(0,1))){
                    defectEntity.setArrayX(ProcessUtil.getNum(defect.getDefectXCoord()));
                }
                defectEntity.setArrayY(ProcessUtil.getNum(defect.getDefectYCoord()));

                if (!StringUtils.isEmpty(layoutPnlDS)) {
                    try {
                        Map<String, Double> dgLines = coordTransformService.big2small(defect.getPanelId(), layoutPnlDS, -ProcessUtil.getDouble(defect.getDefectXCoord()), ProcessUtil.getDouble(defect.getDefectYCoord()));
//                        defectEntity.setArrayGlassS(dgLines.get("glassS"));
//                        defectEntity.setArrayGlassG(dgLines.get("glassG"));
                        defectEntity.setArrayPanelS(dgLines.get("data"));
                        defectEntity.setArrayPanelG(dgLines.get("gate"));

                    } catch (CorrdTransformException e) {
                        logger.warn("defectNo="+defect.getDefectNo()+" opeId="+defect.getOpeId()+"procEndTime="+defect.getEvtTimestamp()+":"+e.getErrorCode());
                    }
                }else{
//                    logger.info("panelId={}不存在layout!",defect.getPanelId());
//                    defectEntity.setArrayGlassS(0.0);
//                    defectEntity.setArrayGlassG(0.0);
                    defectEntity.setArrayPanelS(0.0);
                    defectEntity.setArrayPanelG(0.0);
                }

                defectEntity.setMarkTypeSg("POINT");
                defectEntity.setArrayPanelS1(defectEntity.getS());
                defectEntity.setArrayPanelG1(defectEntity.getG());

                etlDefectVList.add(defectEntity);
            });
        return etlDefectVList;
    }

    //可能存在SS，可能存在****，
    /*private Long getNum(String str,Logger logger){
        Long num;
        try{
            num=Long.valueOf(str);
            return num;
        }catch (Exception e) {
//            logger.info("FormatException: String[{}] cannot be cast to NUMBER", str);
            num=Long.valueOf(-1);
            return num;
        }
    }*/

}
